<template>
	<view class="confirm_container pb_80">
		<view class="fc lh_36 fb fc_zhured" style="background: #FFE9E9;" v-if="dataInfo.preOrderType==6||dataInfo.preOrderType==7">
			一经兑换，不能取消
		</view>
		<AddressInfo :data="currentAddress" @click.native="addressPopupShow = true" />
		<template v-if="dataInfo.preOrderType!=6&&preOrderTypeid==''" >
			<view class="cell">
				<view class="fx fx_nw aic">
					<view class="fc_999 fx_1 pr_8">
						配送方式
					</view>
					<view class="fx_2">
						<u-radio-group v-model="params.deliveryWay" placement="row" @change="handleComputed">
							<u-radio activeColor="#F08519" label="自提" :name="1"></u-radio>
							<u-radio activeColor="#F08519" label="物流" :name="2"
								:disabled="isOnlyPlatform||isVip"></u-radio>
						</u-radio-group>
					</view>
				</view>
			</view>
			<view class="cell" v-if="params.deliveryWay==2&&appType==base.ADMIN_TYPE">
				<view class="fx fx_nw aic">
					<view class="fc_999 fx_1 pr_8">
						物流配送
					</view>
					<view class="fx_2">
						<u-radio-group v-model="params.logisticsDelivery" placement="row"
							@change="handleChangeLogistics">
							<u-radio activeColor="#F08519" label="平台物流" :name="1"></u-radio>
							<u-radio activeColor="#F08519" label="指定物流" :name="2"></u-radio>
						</u-radio-group>
					</view>
				</view>
			</view>
			<view class="cell" v-if="params.deliveryWay==2&&params.logisticsDelivery==2">
				<view class="fx fx_nw aic" @click="logisticsPopupShow = true">
					<view class="fc_999 fx_1 pr_8">
						物流公司
					</view>
					<view class="fx_2 fx jce iac">
						<text class="mr_8 fc_999">
							{{currentLogistics.name||''}}
						</text>
						<u-icon name="arrow-right" color="#666" size="22rpx"></u-icon>
					</view>
				</view>
			</view>
			<template v-if="params.logisticsDelivery==1">
				<view class="cell" v-if="params.deliveryWay==2">
					<view class="fx fx_nw">
						<view class="fc_999 fx_1 pr_8">
							小区类型
						</view>
						<view class="fx_2">

							<u-radio-group v-model="params.villageType" placement="row"
								@change="handleChangeillageType">
								<u-radio activeColor="#F08519" label="电梯" :name="1"></u-radio>
								<u-radio activeColor="#F08519" label="楼梯(可能有上楼费)" :name="2"></u-radio>
							</u-radio-group>
							<view class="mt_8" v-if="params.villageType==2">
								<u--input type="number" v-model="params.floorNumber" fontSize="22rpx"
									placeholder="请输入楼层，地下室或阁楼需要计入" @blur="handleComputed" />
							</view>
						</view>
					</view>
				</view>
				<view class="cell" v-if="params.deliveryWay==2">
					<view class="fx fx_nw aic">
						<view class="fc_999 fx_1 pr_8">
							是否安装
						</view>
						<view class="fx_2">
							<u-radio-group v-model="params.isInstall" placement="row" @change="handleComputed">
								<u-radio activeColor="#F08519" label="是" :name="true"></u-radio>
								<u-radio activeColor="#F08519" label="否" :name="false"></u-radio>
							</u-radio-group>
						</view>
					</view>
				</view>
			</template>

			<view class="cell" v-if="!isSingle">
				<view class="fx fx_nw aic">
					<view class="fc_999 fx_1 pr_8">
						是否一起发货
					</view>
					<view class="fx_2">
						<u-radio-group v-model="params.isSendTogether" placement="row" @change="handleComputed">
							<u-radio activeColor="#F08519" label="是" :name="true"></u-radio>
							<u-radio activeColor="#F08519" label="否" :name="false"></u-radio>
						</u-radio-group>
					</view>
				</view>
			</view>
			<view class="cell" v-if="params.deliveryWay==2">
				<view class="fx fx_nw aic" @click="dateShow = true">
					<view class="fc_999 fx_1 pr_8">
						期望收货时间
					</view>
					<view class="fx_2 fx jce iac">
						<text class="mr_8 fc_999">
							{{params.expectedDeliveryTime}}
						</text>
						<u-icon name="arrow-right" color="#666" size="22rpx"></u-icon>
					</view>
				</view>
			</view>
		</template>
		<view class="cell" v-for="item,index in dataInfo.orderBrandInfoList" :key="index">
			<view class="fx aic bob_1 boc_e6 pb_12">
				<uni-icons class="mr_4" custom-prefix="iconfont" type="icon-shangdian" color="#333"
					size="32rpx"></uni-icons>
				<text class="ml_4">{{item.brandName||''}}</text>
			</view>
			<view v-for="item1,index1 in item.orderBrandProductList" :key="index1">
				<view class="ptb_12">
					
					<GoodsCard :data="goodsItem(item1)" :goodsType="dataInfo.preOrderType" :toDetail="false"
						type="info-card" />
				</view>
				<view class="fx jcb mt_4"
					v-if="params.deliveryWay==2&&dataInfo.preOrderType!=6&&dataInfo.logisticsDelivery!=2&&preOrderTypeid==''">
					<text class="fc_999">配送费</text>
					<text>{{item1.deliveryCost ? ('￥'+item1.deliveryCost): (dataInfo.preOrderType == 5 ? '包邮' : '以线下门店为准')}}</text>
				</view>
				<view class="fx jcb mt_12" v-if="params.deliveryWay==2&&params.isInstall&&preOrderTypeid==''">
					<text class="fc_999">安装费</text>
					<text>{{item1.installCost ? ('￥'+item1.installCost): (dataInfo.preOrderType == 5 ? '包邮' : '以线下门店为准')}}</text>
				</view>
				<view class="fx jcb mt_12" v-if="params.deliveryWay==2&&params.villageType==2">
					<text class="fc_999">上楼费</text>
					<text>{{floorCoast(item1) ? ('￥'+floorCoast(item1)): (dataInfo.preOrderType == 5 ? '包邮' : '以线下门店为准')}}</text>
				</view>
				<view class="mt_12 fc_999">
					购买留言
				</view>
				<textarea class="bo_1 boc_ccc w100 minh_54 mt_8 br_4 box lh_18" v-model="item1.mark"
					:auto-height="true" maxlength="200"></textarea>
			</view>
		</view>

		<view class="cell" v-if="preOrderTypeid!=''">
			<view class="mt_12 fc_999">
				中奖说明
			</view>
			<view class="u-body-item u-flex u-row-between u-p-b-0">
				<view class="u-body-item-title u-line-2">{{content}}</view>
			</view>
		</view>
		<view class="cell" v-if="preOrderTypeid==''">
			<view class="fx fx_nw aic jcb">
				<text class="fc_999 pr_8">
					订单金额
				</text>
				<text
					v-if="dataInfo.preOrderType==6">{{dataInfo.integral||0}}积分+¥{{price.afterDiscountAmount||0}}</text>
				<text v-else>
					￥{{price.afterDiscountAmount||0}}
				</text>
			</view>
			<view class="fx fx_nw aic jcb mt_12"
				v-if="params.deliveryWay==2&&dataInfo.preOrderType!=6&&dataInfo.logisticsDelivery!=2">
				<text class="fc_999 pr_8">
					配送费合计
				</text>
				<text>
					{{price.totalDeliveryCost ? ('￥'+price.totalDeliveryCost): (dataInfo.preOrderType == 5 ? '包邮' : '以线下门店为准')}}
				</text>
			</view>
			<view class="fx fx_nw aic jcb mt_12" v-if="params.deliveryWay==2&&params.isInstall">
				<text class="fc_999 pr_8">
					安装费合计
				</text>
				<text>
					{{price.totalInstallCost ? ('￥'+price.totalInstallCost): (dataInfo.preOrderType == 5 ? '包邮' : '以线下门店为准')}}
				</text>
			</view>
			<view class="fx fx_nw aic jcb mt_12" v-if="params.deliveryWay==2&&params.villageType==2">
				<text class="fc_999 pr_8">
					上楼费合计
				</text>
				<text>
					{{price.totalUpstairsCost ? ('￥'+price.totalUpstairsCost): (dataInfo.preOrderType == 5 ? '包邮' : '以线下门店为准')}}
				</text>
			</view>
		</view>
		<view class="cell" v-if="dataInfo.preOrderType!=6&&preOrderTypeid==''">

			<view class="fx fx_nw aic jcb" @click="couponPopupShow=true">
				<text class="pr_8">
					优惠券
				</text>
				<view class="fx aic jce">
					<text class="fc_primary mr_8" v-if="currentCoupon">{{currentCoupon.discountCouponName||''}}</text>
					<u-icon name="arrow-right" color="#666" size="22rpx"></u-icon>
				</view>
			</view>
			<!-- <template v-if="appType == base.ADMIN_TYPE">
				<view class="fx fx_nw aic jcb mt_20">
					<text class="pr_8">

						金豆抵扣(共{{youJiaBiTotal||0}})
					</text>
					<u-switch v-model="useYouJiaBi" activeColor="#F08519" @change="handleSwitchYouJiaBi"
						:disabled="youJiaBiTotal==0"></u-switch>
				</view>
				<view class="fx fx_nw aic jcb mt_12" v-if="useYouJiaBi">
					<text class="fc_999 pr_8"> -->
						<!-- {{youJiaBiValue||0}}金豆抵扣￥{{youJiaBiValue||0}} -->
				<!-- 	</text>
					<input class="bc_f6 br_4 fr fz_12 width_100 plr_8" type="number" :value="params.youjiaDiscountNum"
						@blur="handleBlurYoujia" />
				</view>
			</template> -->
		</view>
		<u-datetime-picker ref="datetimePicker" :minDate="minDate" :formatter="formatter" :show="dateShow"
			v-model="datatime" mode="date" @confirm="handleConfrimDateTime" :confirmColor="'#F08519'"
			@cancel="dateShow=false"></u-datetime-picker>

		<view class="pf b_0 l_0 r_0 fx aic jcb pt_8 plr_12 bc_fff zbi_50 btn_wrap" v-if="preOrderTypeid==''">
			<view class="fz_12">
				<text>共 {{dataInfo.orderProNum||0}} 件，应付</text>
				<text class="fc_zhured fb"	
					v-if="dataInfo.preOrderType==6">{{dataInfo.integral||0}}积分+¥{{price.afterDiscountAmount||0}}</text>
				<text class="fc_zhured fb" v-else>￥{{price.payFee||0}}</text>
			</view>
			<u-button :custom-style="{height: '72rpx', width: '186rpx'}" class="custom_btn_wrap" type="primary"
				shape="circle" @click="handleConfirm">{{dataInfo.preOrderType==6?'确认兑换':'确认下单'}}</u-button>
		</view>
		<view class="pf b_0 l_0 r_0 fx aic jcb pt_8 plr_12 bc_fff zbi_50 btn_wrap" v-if="preOrderTypeid!=''">

			<u-button :custom-style="{height: '72rpx', width: '80%',left:'60rpx'}"
				class="custom_btn_wrappreOrderTypeid" type="primary" shape="circle"
				@click="handleConfirms">确定领奖</u-button>
		</view>

		<AddressWindow :data="addressList" :currentId="currentAddress.id||null" :visible.sync="addressPopupShow"
			@select="handleSelectAddress" />
		<LogisticsWindow :data="logisticsList" :currentId="currentLogistics.id||null" :visible.sync="logisticsPopupShow"
			@select="handleSelectLogistics" />

		<CouponWindow :productId="productIds" :productType="productType" :visible.sync="couponPopupShow"
			@select="handleSelectCoupon" />
		<PayPass :mask="true" ref="payRef" @submit="submitpay">
			<view class="fc fz_32 fb pb_22">
				{{dataInfo.integral||0}}积分
			</view>
		</PayPass>
	</view>
</template>

<script>
	import AddressInfo from '@/components/goods/AddressInfo'
	import GoodsCard from '@/components/goods/GoodsCard'
	import AddressWindow from '../components/AddressWindow'
	import LogisticsWindow from '../components/LogisticsWindow'
	import CouponWindow from '../components/CouponWindow'
	import PayPass from '@/components/PayPass'
	import {
		mapState
	} from 'vuex'
	import api from '@/service/config/api.js'
	export default {
		components: {
			AddressInfo,
			GoodsCard,
			AddressWindow,
			LogisticsWindow,
			CouponWindow,
			PayPass
		},
		data() {
			return {
				base: this.$base,
				dateShow: false,
				date: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd'),
				addressPopupShow: false,
				couponPopupShow: false,
				logisticsPopupShow: false, // 物流公司弹窗
				id: null,
				dataInfo: {},
				initAddressId: '',
				currentAddress: null,
				addressList: [],
				logisticsList: [], // 配送物流
				currentLogistics: null,
				datatime: '',
				totalNum: 0,
				params: {
					deliveryWay: 2,
					logisticsDelivery: 1,
					villageType: 1,
					floorNumber: '',
					isInstall: true,
					isSendTogether: true,
					logisticsManageId: '',
					expectedDeliveryTime: '',
					youjiaDiscountNum: 0,
				},
				price: {}, // 价格
				minDate: new Date().getTime(),
				useYouJiaBi: false, // 使用金豆
				youJiaBiValue: 0, // 金豆数量
				youJiaBiInputValue: null, // 金豆数量
				youJiaBiTotal: 0, // 我的金豆
				youJiaBiMax: 0, // 最大金豆
				tempParams: {}, // 临时存params
				userInfo: this.$storage.getItem('basicUnserInfo') || {},
				isPaying: false, // 支付中
				currentCoupon: null,
				productIds: [], // 商品id集合
				productType: 1,
				isOnlyPlatform: false,
				isVip: false,
				content: '',
				preOrderTypeid: '', //抽奖进入
			}
		},
		computed: {
			...mapState(['appType']),
			// 是否单商品
			isSingle() {
				if (this.dataInfo.orderBrandInfoList && this.dataInfo.orderBrandInfoList.length) {
					let count = this.dataInfo.orderBrandInfoList.reduce((num, item) => {
						return num + ((item.orderBrandProductList && item.orderBrandProductList.length) ? item
							.orderBrandProductList
							.length : 0)
					}, 0)
					return count <= 1
				} else {
					return true
				}

			},
			floorCoast() {
				return item => this.$utils.floatMul(this.$utils.floatMul(this.params.floorNumber || 0, item.upstairsCost ||
					0), item.payNum)
			},
			installCost() {
				return item => this.$utils.floatMul(item.payNum || 0, item.installCost || 0)
			},
			goodsItem() {
				return item => {
					if (this.dataInfo.preOrderType == 2 && this.dataInfo.seckillGoodsRule) {
						return this.dataInfo.seckillGoodsRule.productId == item.productId ? {
							...item,
							...this.dataInfo
							.seckillGoodsRule
						} : item
					}
					if (this.dataInfo.preOrderType == 3 && this.dataInfo.bargainirgGoodsRule) {
						return this.dataInfo.bargainirgGoodsRule.productId == item.productId ? {
							...item,
							...this.dataInfo
							.bargainirgGoodsRule
						} : item
					}
					if (this.dataInfo.preOrderType == 5 && this.dataInfo.groupGoodsRule) {
						return this.dataInfo.groupGoodsRule.productId == item.productId ? {
							...item,
							...this.dataInfo
							.groupGoodsRule
						} : item
					}
					return item
				}
			},
			zeroPrice() {
				return item => {
					const data = item ? ('￥'+item): (this.dataInfo.preOrderType == 5 ? '包邮' : '以线下门店为准')
					console.log(99999,item,data)
					return (item ? ('￥'+item): (this.dataInfo.preOrderType == 5 ? '包邮' : '以线下门店为准'))
				}
			}
		},
		watch: {
			'params.logisticsDelivery': {
				handler(newVal) {
					if (newVal != 2) {
						this.currentLogistics = null
					}
				}
			},
			currentAddress: {
				handler(newVal) {
					if (newVal && newVal.id) {
						this.$set(this.params, 'addressId', newVal.id)
						this.handleComputed()
					} else {
						this.$delete(this.params, 'addressId')
					}
				},
				deep: true,
				init: true,
			}
		},
		onLoad(options) {
			this.id = options.order
			this.content = options.content
			this.preOrderTypeid = options.preOrderTypeid
			setTimeout(() => {
				// this.$refs.payRef.show()
			}, 1000)
		},
		onReady() {
			// 微信小程序需要用此写法
			this.$refs.datetimePicker.setFormatter(this.formatter)
		},
		onShow() {
			this.userInfo = this.$storage.getItem('basicUnserInfo') || {}
			if (this.id) {
				this.getData()
			} else {
				this.$utils.showToast('订单不存在', 1500, 1)
			}
		},
		onHide() {
			this.currentAddress = null
			this.addressPopupShow = false
			this.payNum = 0
		},
		methods: {
			paymentCallback() {
				api.post('/order/api/order/wachatPayCallback').then(res => {
					uni.redirectTo({
						url: `/pages/goods/pages/success?type=order&createOrderTime=${res.data.createOrderTime}&gainIntegral=${res.data.gainIntegral}&orderNo=${res.data.orderNo}&orderId=${res.data.orderId}&orderType=${this.dataInfo.preOrderType}&groupGoodsRecordId=${res.data.groupGoodsRecordId}`
					})
				})
			},
			getData() {
				this.$utils.loading()
				api.get('/order/api/order/loadPreOrder/' + this.id, {}, {
					noToast: true
				}).then(res => {
					this.dataInfo = res.data
					const originList = []
					let originFlag = false
					this.productType = (res.data.preOrderType > 1 && res.data.preOrderType < 6) ? 1 : 2
					this.handleComputed()
					let markList = []
					if (res.data && res.data.orderBrandInfoList) {
						res.data.orderBrandInfoList.forEach(item => {
							item.orderBrandProductList.forEach(item1 => {
								if (item1.isVip) {
									this.isVip = true
								}
								if (originList.length && !originList.some(item2 => item2 == item1
										.origin)) {
									originFlag = true
								} else {
									originList.push(item1.origin)
								}
								this.productIds.push(item1.productId)
								item1.mark = ''
								this.totalNum += item1.payNum
							})
						})
						this.$set(this.params, 'markList', markList)
						if (originFlag) {
							this.isOnlyPlatform = true
							this.$set(this.params, 'deliveryWay', 1)
						}
						if (this.isVip) {
							this.$set(this.params, 'deliveryWay', 1)
						}
					}
					if (res.data) {
						this.youJiaBiMax = res.data.youjiaDiscountMax
					}
					if (res.data.preOrderType == 6) {
						this.$set(this.params, 'isInstall', false)
						this.$set(this.params, 'villageType', 1)
						// this.handleComputed()
					}
					this.getYoujiabi()
					api.get('/user/api/UserAddress/list').then(res => {
						this.addressList = res.data;

						this.currentAddress = this.addressList.find(item => this.initAddressId ? item.id ==
							this.initAddressId : item.isDefault == 1)
					})
					api.get('/user/api/LogisticsManage/list').then(res => {
						this.logisticsList = res.data;
					})
				}).catch(err => {
					// this.$utils.showToast(err, 1500, 1)
				})
			},
			getYoujiabi() {
				api.get('/user/api/myLegumes', {}, {
					noToast: true,
					noHideLoading: true
				}).then(res => {
					this.youJiaBiTotal = res.data.youJiaBalance || 0
				})
			},
			// 格式化日期弹窗
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				return value
			},
			handleChangeLogistics(value) {
				console.log(value)
				if (value == 2) {
					this.$set(this.params, 'isInstall', false)
					this.$set(this.params, 'villageType', 1)
				}
				this.handleComputed()
			},
			handleChangeillageType() {
				this.$set(this.params, 'floorNumber', '')
				this.handleComputed()
			},
			// 计算价格
			handleComputed() {
				return new Promise((resolve, reject) => {
					console.log('this.params', this.params)
					const params = JSON.parse(JSON.stringify(this.params))
					let params1 = {}
					if (params.deliveryWay == 1) {
						const {
							deliveryWay,
							isSendTogether,
							couponId
						} = params
						params1 = {
							deliveryWay,
							isSendTogether,
							couponId
						}
					} else {
						params1 = params
					}
					params1 = {
						...params1,

						// ...this.currentAddress ? {
						// 	addressId: this.currentAddress.id
						// } : {},
						preOrderNo: this.id,
					}
					api.post('/order/api/order/computedPrice', params1, {
						noHideLoading: true
					}).then(res => {
						this.price = res.data
						if (res.data && res.data.orderBrandInfoList && res.data.orderBrandInfoList
							.length) {
							const orderBrandInfoList = this.dataInfo.orderBrandInfoList.map((item,
								index) => {
								return {
									...item,
									orderBrandProductList: item.orderBrandProductList.map((item1,
										index1) => {
										return {
											...res.data.orderBrandInfoList[index]
											.orderBrandProductList[index1],
											mark: item1.mark
										}
									})
								}
							})
							console.log('orderBrandInfoList--', orderBrandInfoList)
							this.$set(this.dataInfo, 'orderBrandInfoList', orderBrandInfoList)
						}
						resolve()
					}).catch(() => {
						reject()
					})
				})
			},
			handleConfrimDateTime({
				value
			}) {
				this.datatime = value
				this.$set(this.params, 'expectedDeliveryTime', uni.$u.timeFormat(value, 'yyyy-mm-dd'))
				this.dateShow = false
			},
			handleSelectAddress(current) {
				this.currentAddress = current

				// this.handleComputed()
			},
			handleSelectLogistics(current) {
				this.currentLogistics = current
			},

			// 下单兑奖
			handleConfirms() {
				if (!this.currentAddress) {
					return uni.showModal({
						title: '提示',
						content: '您还未添加收货地址喔~',
						confirmColor: '#F08519',
						cancelColor: '#999999',
						confirmText: '去添加',
						cancelText: '我再想想',
						success: res => {
							if (res.confirm) {
								this.addressPopupShow = true
							}
						}
					})
				}

				api.post('/order/api/order/createOrder', {
					preOrderNo: this.id,
					addressId: this.currentAddress.id,
					deliveryWay: 2
				}).then(res => {
					console.log("下单返回", res);
					this.$utils.showToast('兑奖成功', 1500, 0, '', 'success')
					let url =
						`/pages/goods/pages/success?type=order&createOrderTime=${res.data.createOrderTime}&gainIntegral=${res.data.gainIntegral}&orderNo=${res.data.orderNo}&orderId=${res.data.orderId}&orderType=${this.dataInfo.preOrderType}&goodsId=${this.dataInfo.groupGoodsRecordId}&groupGoodsRecordId=${res.data.groupGoodsRecordId}&residueCount=${res.data.residueCount}`
					uni.redirectTo({
						url: url + `&goodsId=${this.dataInfo.combinationId}`
					})
				}).finally(() => {
					uni.hideLoading()
				})
			},

			handleConfirm(noHideLoading = false) {
				if (this.params.villageType == 2 && !this.params.floorNumber) {
					return this.$utils.showToast('请输入楼层')
				}
				if (this.params.logisticsDelivery == 2 && !this.currentLogistics) {
					return this.$utils.showToast('请选择物流公司')
				}
				if (!this.currentAddress) {
					return uni.showModal({
						title: '提示',
						content: '您还未添加收货地址喔~',
						confirmColor: '#F08519',
						cancelColor: '#999999',
						confirmText: '去添加',
						cancelText: '我再想想',
						success: res => {
							if (res.confirm) {
								this.addressPopupShow = true
							}
						}
					})
				}
				this.$utils.loading()
				const params = JSON.parse(JSON.stringify(this.params))
				let params1 = {}
				if (params.deliveryWay == 1) {
					const {
						deliveryWay,
						isSendTogether,
						couponId
					} = params
					params1 = {
						deliveryWay,
						isSendTogether,
						couponId
					}
				} else {
					params1 = params
				}
				// 商铺留言
				const markList = []
				if (this.dataInfo.orderBrandInfoList) {
					this.dataInfo.orderBrandInfoList.forEach(item => {
						item.orderBrandProductList.forEach(item1 => {
							if (item1.mark) {
								markList.push({
									productId: item1.productId,
									mark: item1.mark
								})
							}
						})
					})
				}
				if (markList.length) {
					params1.markList = markList
				}
				params1 = {
					...params1,
					preOrderNo: this.id,
					addressId: this.currentAddress.id,
					...this.currentLogistics ? {
						logisticsManageId: this.currentLogistics.id
					} : {}
				}
				this.handleComputed(true).then(() => {
					if (this.dataInfo.preOrderType == 6) {
						this.tempParams = params1
						uni.hideLoading()
						if (this.dataInfo.afterDiscountAmount) {
							this.submitpay()
						} else {
							if (!this.userInfo.setPayPassword) {
								this.$utils.showToast('请设置交易密码')
								return uni.navigateTo({
									url: '/pages/person/pages/pay_password?settingType=confirm&reset=true'
								})
							}
							this.$refs.payRef.show()
							console.log('进入');
						}

					} else {
						console.log('进入0');
						api.post('/order/api/order/createOrder', params1).then(res => {
							console.log(res)
							let url =
								`/pages/goods/pages/success?type=order&createOrderTime=${res.data.createOrderTime}&gainIntegral=${res.data.gainIntegral}&orderNo=${res.data.orderNo}&orderId=${res.data.orderId}&orderType=${this.dataInfo.preOrderType}&goodsId=${this.dataInfo.groupGoodsRecordId}&groupGoodsRecordId=${res.data.groupGoodsRecordId}&residueCount=${res.data.residueCount}`
							uni.redirectTo({
								url: url + `&goodsId=${this.dataInfo.combinationId}`
							})
						}).finally(() => {
							uni.hideLoading()
						})
					}
				}).catch(() => {
					uni.hideLoading()
				})
			},
			//输入支付密码
			submitpay(pass) {
				uni.showLoading({
					title: '支付中',
					mask: true
				})
				if (pass) {
					return api.post('/order/api/order/createOrder', {
						...this.tempParams,
						payPassword: pass.value
					}).then(res => {
						let url =
							`/pages/goods/pages/success?type=order&createOrderTime=${res.data.createOrderTime}&gainIntegral=${res.data.gainIntegral}&orderNo=${res.data.orderNo}&orderId=${res.data.orderId}&orderType=${this.dataInfo.preOrderType}&goodsId=${this.dataInfo.groupGoodsRecordId}&groupGoodsRecordId=${res.data.groupGoodsRecordId}&residueCount=${res.data.residueCount}`
						uni.redirectTo({
							url
						})
					})
				}
				if (this.price.afterDiscountAmount) {
					return api.post('/order/api/order/createOrder', {
						...this.tempParams
					}, {
						noHideLoading: true
					}).then(res => {
						uni.login({
							success: (res1) => {
								api.post('/order/api/order/payment', {
									orderNo: res.data.orderNo,
									type: 'APP-MINI',
									tradeType: 'JSAPI',
									code: res1.code
								}, {
									noHideLoading: true
								}).then(res2 => {
									const {
										appid,
										timeStamp,
										nonceStr,
										prepayId,
										signType,
										paySign,
									} = res2.data.payInfo
									uni.requestPayment({
										provider: 'wxpay',
										...res2.data.payInfo,
										success: () => {
											let url =
												`/pages/goods/pages/success?type=order&createOrderTime=${res.data.createOrderTime}&gainIntegral=${res.data.gainIntegral}&orderNo=${res.data.orderNo}&orderId=${res.data.orderId}&orderType=${this.dataInfo.preOrderType}&goodsId=${this.dataInfo.groupGoodsRecordId}&groupGoodsRecordId=${res.data.groupGoodsRecordId}&residueCount=${res.data.residueCount}`
											uni.redirectTo({
												url
											})
										},
										fail: (err) => {
											this.$utils.showToast('支付失败')
											setTimeout(() => {
												uni.redirectTo({
													url: '/pages/person/pages/order_detail?id=' +
														res.data
														.orderId
												})
											}, 1500)
										}
									});
								}).catch(() => {
									setTimeout(() => {
										uni.redirectTo({
											url: '/pages/person/pages/order_detail?id=' +
												res.data
												.orderId
										})
									}, 1500)
								}).finally(() => {
									uni.hideLoading()
								})
							}
						})

					}).catch(() => {
						uni.hideLoading()
					})
				}
				api.post('/order/api/order/createOrder', this.tempParams).then(res => {
					console.log(res)
					uni.redirectTo({
						url: `/pages/goods/pages/success?type=order&createOrderTime=${res.data.createOrderTime}&gainIntegral=${res.data.gainIntegral}&orderNo=${res.data.orderNo}&orderId=${res.data.orderId}&orderType=${this.dataInfo.preOrderType}&groupGoodsRecordId=${res.data.groupGoodsRecordId}&residueCount=${res.data.residueCount}`
					})
				})
				if (this.payType == '0') {
					// payOrder({
					// 	payType: 0,
					// 	amount: this.orderInfo.payPrice,
					// 	payPwd: pass.value,
					// 	uid: this.uid,
					// 	orderId: this.orderInfo.id,
					// 	videoUrl: this.videoUrl
					// }).then(() => {
					// 	uni.hideLoading();
					// 	uni.redirectTo({
					// 		url: `/pages/order/success?sign=${this.productInfo.isSignElectronicContract}&orderId=${this.orderInfo.id}`
					// 	})
					// }).catch(err => {
					// 	if (err == '订单已超时') {
					// 		setTimeout(() => {
					// 			uni.redirectTo({
					// 				url: '/pages/order/detail?id=' + this.orderInfo.id
					// 			})
					// 		}, 1000)
					// 	}
					// 	uni.hideLoading();
					// })
				} else {
					// this.cashPay(pass);
				}
			},
			handleBlurYoujia(e) {
				let youJiaBiInputValue = this.youJiaBiInputValue
				let youJiaBiTotal = this.youJiaBiTotal
				let youJiaBiValue = this.params.youjiaDiscountNum
				if (e.detail.value) {
					if (e.detail.value * 1 > youJiaBiTotal) {
						youJiaBiInputValue = youJiaBiTotal
						youJiaBiValue = youJiaBiTotal
						if (youJiaBiValue > (this.dataInfo.youjiaDiscountMax || 0)) {

							this.$utils.showToast(`本次最多可使用${this.dataInfo.youjiaDiscountMax || 0}个金豆`)
							youJiaBiInputValue = this.dataInfo.youjiaDiscountMax
							youJiaBiValue = this.dataInfo.youjiaDiscountMax
						}
					} else {
						youJiaBiValue = e.detail.value * 1 || 0
						if (youJiaBiValue > (this.dataInfo.youjiaDiscountMax || 0)) {

							this.$utils.showToast(`本次最多可使用${this.dataInfo.youjiaDiscountMax || 0}个金豆`)
							youJiaBiInputValue = this.dataInfo.youjiaDiscountMax
							youJiaBiValue = this.dataInfo.youjiaDiscountMax
						}
					}
				} else {
					youJiaBiValue = 0
				}
				this.youJiaBiInputValue = youJiaBiInputValue
				this.$set(this.params, 'youjiaDiscountNum', youJiaBiValue)
				this.handleComputed()
			},
			handleSwitchYouJiaBi(e) {
				if (e) {
					this.$set(this.params, 'youjiaDiscountNum', this.params.youjiaDiscountNum > this.youJiaBiMax ? this
						.youJiaBiMax : this.params.youjiaDiscountNum)
				} else {
					this.$set(this.params, 'youjiaDiscountNum', 0)
					this.youJiaBiInputValue = ''
				}
				this.handleComputed()
			},
			handleSelectCoupon(data) {
				this.currentCoupon = data
				this.couponPopupShow = false
				this.$set(this.params, 'couponId', data.id)
				this.handleComputed()
			}
		},

	}
</script>

<style lang="scss" scoped>
	.custom_btn_wrappreOrderTypeid {}

	.cell {
		margin-top: 16rpx;
		padding: 24rpx 32rpx;
		background: #fff;
	}

	/deep/.u-radio+.u-radio {
		margin-left: 48rpx;
	}

	.btn_wrap {
		padding-bottom: calc(20rpx + constant(safe-area-inset-bottom));
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
	}
</style>